Mod_Rewrite voodoo

Mod_Rewrite voodoo

am 04.01.2010 17:33:33 von Reese

Hello everyone,

I am restructuring a Web site and need to move a number of files to
different subdirectories. The files have an embedded date code in
[filename]DDMMYY.ext format, I was hoping to hook the YY.ext portion
to redirect ...05.html files to the 2005/ subdirectory, ...06.html
files to the 2006/ subdirectory, etc.

This shouldn't be that difficult, but I'm not getting anywhere with
the RewriteCond/RewriteRule pairs I've tried so far. Either I get
500 errors, create endless loops or the rule is not applied at all.

How should a rewrite rule like this be formulated?

Reese


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

RE: Mod_Rewrite voodoo

am 05.01.2010 08:52:24 von Boyle Owen

> -----Original Message-----
> From: Reese [mailto:howell.r@inkworkswell.com]=20
> Sent: Monday, January 04, 2010 5:34 PM
> To: users@httpd.apache.org
> Subject: [users@httpd] Mod_Rewrite voodoo
>=20
> Hello everyone,
>=20
> I am restructuring a Web site and need to move a number of files to
> different subdirectories. The files have an embedded date code in
> [filename]DDMMYY.ext format, I was hoping to hook the YY.ext portion
> to redirect ...05.html files to the 2005/ subdirectory, ...06.html
> files to the 2006/ subdirectory, etc.
>=20
> This shouldn't be that difficult, but I'm not getting anywhere with
> the RewriteCond/RewriteRule pairs I've tried so far. Either I get
> 500 errors, create endless loops or the rule is not applied at all.
>=20
> How should a rewrite rule like this be formulated?

What did you try so far?

Rgds,
Owen Boyle
Disclaimer: Any disclaimer attached to this message may be ignored.=20

>=20
> Reese
>=20
>=20
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP=20
> Server Project.
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>=20
>=20
=20
This message is for the named person's use only. It may contain =
confidential, proprietary or legally privileged information. If you =
receive this message in error, please notify the sender urgently and =
then immediately delete the message and any copies of it from your =
system. Please also immediately destroy any hardcopies of the message.=20
The sender's company reserves the right to monitor all e-mail =
communications through their networks.

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 05.01.2010 23:43:37 von Igor Cicimov

--001636b2bcbb9c9201047c729164
Content-Type: text/plain; charset=ISO-8859-1

You can try this

RewriteEngine On
RewriteRule (.*)([0-9]{2}).html$ /20$2/$1$2.html [R,L]

I wrote it on the go and haven't tested it. It might be done in different
way probably but give this one a go and will see what can we do if it is not
working.

Cheers

On Tue, Jan 5, 2010 at 6:52 PM, Boyle Owen wrote:

> > -----Original Message-----
> > From: Reese [mailto:howell.r@inkworkswell.com]
> > Sent: Monday, January 04, 2010 5:34 PM
> > To: users@httpd.apache.org
> > Subject: [users@httpd] Mod_Rewrite voodoo
> >
> > Hello everyone,
> >
> > I am restructuring a Web site and need to move a number of files to
> > different subdirectories. The files have an embedded date code in
> > [filename]DDMMYY.ext format, I was hoping to hook the YY.ext portion
> > to redirect ...05.html files to the 2005/ subdirectory, ...06.html
> > files to the 2006/ subdirectory, etc.
> >
> > This shouldn't be that difficult, but I'm not getting anywhere with
> > the RewriteCond/RewriteRule pairs I've tried so far. Either I get
> > 500 errors, create endless loops or the rule is not applied at all.
> >
> > How should a rewrite rule like this be formulated?
>
> What did you try so far?
>
> Rgds,
> Owen Boyle
> Disclaimer: Any disclaimer attached to this message may be ignored.
>
> >
> > Reese
> >
> >
> > ------------------------------------------------------------ ---------
> > The official User-To-User support forum of the Apache HTTP
> > Server Project.
> > See for more info.
> > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > " from the digest: users-digest-unsubscribe@httpd.apache.org
> > For additional commands, e-mail: users-help@httpd.apache.org
> >
> >
>
> This message is for the named person's use only. It may contain
> confidential, proprietary or legally privileged information. If you receive
> this message in error, please notify the sender urgently and then
> immediately delete the message and any copies of it from your system. Please
> also immediately destroy any hardcopies of the message.
> The sender's company reserves the right to monitor all e-mail
> communications through their networks.
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

--001636b2bcbb9c9201047c729164
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

You can try this

RewriteEngine On
RewriteRule (.*)([0-9]{2}).html=
$ /20$2/$1$2.html [R,L]

I wrote it on the go and haven't tested =
it. It might be done in different way probably but give this one a go and w=
ill see what can we do if it is not working.


Cheers

On Tue, Jan 5, 2010 at 6:52 PM=
, Boyle Owen < om">Owen.Boyle@six-group.com> wrote:
gmail_quote" style=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0p=
t 0pt 0pt 0.8ex; padding-left: 1ex;">
What did you try so far?



Rgds,

Owen Boyle

Disclaimer: Any disclaimer attached to this message may be ignored.

This message is for the named person's use only. It may contain c=
onfidential, proprietary or legally privileged information. If you receive =
this message in error, please notify the sender urgently and then immediate=
ly delete the message and any copies of it from your system. Please also im=
mediately destroy any hardcopies of the message.


The sender's company reserves the right to monitor all e-mail communica=
tions through their networks.



------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g">users-unsubscribe@httpd.apache.org

=A0 " =A0 from the digest: @httpd.apache.org">users-digest-unsubscribe@httpd.apache.org

For additional commands, e-mail: org">users-help@httpd.apache.org






--001636b2bcbb9c9201047c729164--

Re: Mod_Rewrite voodoo

am 06.01.2010 16:45:29 von Reese

On 05-Jan-10 02:52, Boyle Owen wrote:

>> I am restructuring a Web site and need to move a number of files to
>> different subdirectories. The files have an embedded date code in
>> [filename]DDMMYY.ext format, I was hoping to hook the YY.ext portion
>> to redirect ...05.html files to the 2005/ subdirectory, ...06.html
>> files to the 2006/ subdirectory, etc.


> What did you try so far?


This, which seems to work but is too inclusive - it'll break links
to external sites that have the matching 05.html string:

RedirectMatch (.*)05\.html http://domain.com/2005%1.html

Also this, which surely has syntax and other errors - it doesn't
work at all:

RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule (.*)05\.html$ http://www\.domain\.com\2005$1.html

Reese


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 06.01.2010 19:16:37 von Reese

On 05-Jan-10 17:43, Igor Cicimov wrote:
> You can try this
>
> RewriteEngine On
> RewriteRule (.*)([0-9]{2}).html$ /20$2/$1$2.html [R,L]
>
> I wrote it on the go and haven't tested it. It might be done in different
> way probably but give this one a go and will see what can we do if it is not
> working.

Okay.

Offhand, I'd guess that this would move every file with two digits
in the two spots immediately to the left of the period, to the
subdirectory that corresponds to 20$2 - which may work out okay.
I'm not sure that this would be wanted or needed for files with the
10 (2010) year code however - the site is moving to a blog format
so this won't be an issue moving forward but, the files from 2005
thru 2009 still need to be cleaned up.

I'm also not sure what would prevent this from becoming endlessly
recursive, since the domain/2005/file013105.html file may still
get processed and redirected to domain/2005/2005/file013105.html,
etc. and etc. Is an [L] flag needed or something?

Reese



------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 06.01.2010 21:27:53 von Reese

On 06-Jan-10 13:16, Reese wrote:
> On 05-Jan-10 17:43, Igor Cicimov wrote:
>> You can try this
>>
>> RewriteEngine On
>> RewriteRule (.*)([0-9]{2}).html$ /20$2/$1$2.html [R,L]

> I'm also not sure what would prevent this from becoming endlessly
> recursive, since the domain/2005/file013105.html file may still
> get processed and redirected to domain/2005/2005/file013105.html,
> etc. and etc. Is an [L] flag needed or something?

Ah, it has it, now I see. Since this is expected to be permanent,
then the flags should probably be [L,R=301] shouldn't they?

Also, how would this be disabled for files with a date code that
corresponds to calendar year 2010 (nameDDMMYY.ext)? It is needed
for 2005-2009, but not other years - and not for external links.
So adding RewriteCond %{HTTP_HOST} domain\.com is needed, yes?

Reese


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 06.01.2010 21:50:15 von Patrick Horgan

Reese wrote:
> On 06-Jan-10 13:16, Reese wrote:
>> On 05-Jan-10 17:43, Igor Cicimov wrote:
>>> You can try this
>>>
>>> RewriteEngine On
>>> RewriteRule (.*)([0-9]{2}).html$ /20$2/$1$2.html [R,L]
>
>> I'm also not sure what would prevent this from becoming endlessly
>> recursive, since the domain/2005/file013105.html file may still
>> get processed and redirected to domain/2005/2005/file013105.html,
>> etc. and etc. Is an [L] flag needed or something?
>
> Ah, it has it, now I see. Since this is expected to be permanent,
> then the flags should probably be [L,R=301] shouldn't they?
>
> Also, how would this be disabled for files with a date code that
> corresponds to calendar year 2010 (nameDDMMYY.ext)? It is needed
> for 2005-2009, but not other years - and not for external links.
> So adding RewriteCond %{HTTP_HOST} domain\.com is needed, yes?
>
> Reese
RewriteRule (.*)(0[0-9]).html$ /20$2/$1$2.html [R,L]
>
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server
> Project.
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>



------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 06.01.2010 21:58:48 von Reese

On 06-Jan-10 15:50, Patrick Horgan wrote:

>> So adding RewriteCond %{HTTP_HOST} domain\.com is needed, yes?


> RewriteRule (.*)(0[0-9]).html$ /20$2/$1$2.html [R,L]


Hmmm. So adding more specificity, for years 2005-2009 and only for
the affected domain, this should work:

RewriteCond %{HTTP_HOST} domain\.com
RewriteRule (.*)(0[5-9]).html$ /20$2/$1$2.html [R=301,L]

I'll test it.

Reese


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 06.01.2010 22:23:12 von Igor Cicimov

--00504502c5c2d5fdf2047c858f58
Content-Type: text/plain; charset=ISO-8859-1

One more thing, it will work for this century only since 20xx is hard coded
in the rule. Thought should mention it although it's not going to be your
problem in 2100 haha


On Thu, Jan 7, 2010 at 7:58 AM, Reese wrote:

> On 06-Jan-10 15:50, Patrick Horgan wrote:
>
> So adding RewriteCond %{HTTP_HOST} domain\.com is needed, yes?
>>>
>>
>
> RewriteRule (.*)(0[0-9]).html$ /20$2/$1$2.html [R,L]
>>
>
>
> Hmmm. So adding more specificity, for years 2005-2009 and only for
> the affected domain, this should work:
>
>
> RewriteCond %{HTTP_HOST} domain\.com
> RewriteRule (.*)(0[5-9]).html$ /20$2/$1$2.html [R=301,L]
>
> I'll test it.
>
> Reese
>
>
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

--00504502c5c2d5fdf2047c858f58
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

One more thing, it will work for this century only since 20xx is hard coded=
in the rule. Thought should mention it although it's not going to be y=
our problem in 2100 haha


On Thu, Jan =
7, 2010 at 7:58 AM, Reese < inkworkswell.com">howell.r@inkworkswell.com> wrote:

204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
>On 06-Jan-10 15:50, Patrick Horgan wrote:



204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 204, 204); margin=
: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

So adding RewriteCond %{HTTP_HOST} domain\.com is needed, yes?






eft: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left:=
1ex;">
RewriteRule (.*)(0[0-9]).html$ /20$2/$1$2.html [R,L]






Hmmm. So adding more specificity, for years 2005-2009 and only for

the affected domain, this should work:




RewriteCond %{HTTP_HOST} domain\.com

RewriteRule (.*)(0[5-9]).html$ /20$2/$1$2.html [R=3D301,L]



I'll test it.



Reese






------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g" target=3D"_blank">users-unsubscribe@httpd.apache.org

=A0" =A0 from the digest: httpd.apache.org" target=3D"_blank">users-digest-unsubscribe@httpd.apache.o=
rg


For additional commands, e-mail: org" target=3D"_blank">users-help@httpd.apache.org






--00504502c5c2d5fdf2047c858f58--

Re: Mod_Rewrite voodoo

am 07.01.2010 01:10:26 von Jonesy

On Thu, 7 Jan 2010 08:23:12 +1100, Igor Cicimov wrote:

> One more thing, it will work for this century only since 20xx is hard coded
> in the rule. Thought should mention it although it's not going to be your
> problem in 2100 haha

Actually, it will.
2100 is the last year in *this* century of the Common Era.....



------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Re: Mod_Rewrite voodoo

am 07.01.2010 02:07:11 von Res

On Thu, 7 Jan 2010, Jonesy wrote:

> On Thu, 7 Jan 2010 08:23:12 +1100, Igor Cicimov wrote:
>
>> One more thing, it will work for this century only since 20xx is hard coded
>> in the rule. Thought should mention it although it's not going to be your
>> problem in 2100 haha
>
> Actually, it will.
> 2100 is the last year in *this* century of the Common Era.....

I think what he was saying is, its not going to be _YOUR_ problem.
But hey if you live to be 1 1/2 centuries of age, then I guess it might
be :)


--
Res

"What does Windows have that Linux doesn't?" - One hell of a lot of bugs!

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 07.01.2010 17:13:54 von Reese

On 06-Jan-10 15:58, Reese wrote:

> Hmmm. So adding more specificity, for years 2005-2009 and only for
> the affected domain, this should work:
>
> RewriteCond %{HTTP_HOST} domain\.com
> RewriteRule (.*)(0[5-9]).html$ /20$2/$1$2.html [R=301,L]
>
> I'll test it.


It doesn't seem to be working. Testing for files with the embedded
date code corresponding to years 2005 and 2006 (files with 05.html
and 06.html text strings), I have this:

RewriteEngine On
RewriteCond %{HTTP_HOST} subdomain\.domain\.ext
RewriteRule (.*)(0[5-6]).html$ /20$2/$1$2.html [R=301,L]
RewriteEngine Off

and, there is no redirection happening at all, in the sandbox.
I did a quick test on the live files after copying (not moving)
them to their target destination, no effect outside of the
sandbox either.

What am I missing?

Reese


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 07.01.2010 17:22:19 von Eric Covener

On 1/7/10, Reese wrote:

> RewriteEngine On
> RewriteCond %{HTTP_HOST} subdomain\.domain\.ext
> RewriteRule (.*)(0[5-6]).html$ /20$2/$1$2.html [R=301,L]
> RewriteEngine Off

You don't bookend your rules with on/off.

--
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 07.01.2010 18:18:10 von Reese

On 07-Jan-10 11:22, Eric Covener wrote:
> On 1/7/10, Reese wrote:
>
>> RewriteEngine On
>> RewriteCond %{HTTP_HOST} subdomain\.domain\.ext
>> RewriteRule (.*)(0[5-6]).html$ /20$2/$1$2.html [R=301,L]
>> RewriteEngine Off
>
> You don't bookend your rules with on/off.

Meaning what, exactly? This is the only rewrite rule for the subdomain.
Should the rule be placed in the parent domain instead? What?

Reese



------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 07.01.2010 18:24:35 von Tom Evans

On Thu, Jan 7, 2010 at 5:18 PM, Reese wrote:
> On 07-Jan-10 11:22, Eric Covener wrote:
>>
>> On 1/7/10, Reese wrote:
>>
>>>  RewriteEngine On
>>>  RewriteCond %{HTTP_HOST} subdomain\.domain\.ext
>>>  RewriteRule (.*)(0[5-6]).html$ /20$2/$1$2.html [R=3D301,L]
>>>  RewriteEngine Off
>>
>> You don't bookend your rules with on/off.
>
> Meaning what, exactly? This is the only rewrite rule for the subdomain.
> Should the rule be placed in the parent domain instead? What?
>
> Reese
>

http://lmgtfy.com/?q=3Dbookend

"RewriteEngine Off" disables the rewrite engine, so that rewrite rules
are not applied. Seems unlikely that is what you intended.

Cheers

Tom

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 07.01.2010 18:36:19 von Reese

On 07-Jan-10 12:24, Tom Evans wrote:

> http://lmgtfy.com/?q=bookend

Oh, thanks. I didn't know what shelfspace keepers were. @@

> "RewriteEngine Off" disables the rewrite engine, so that rewrite rules
> are not applied. Seems unlikely that is what you intended.

From that, I'd agree with you. My understanding was:

Do X
....does X
....after doing X
Stop doing X

I'm missing something here. Maybe it's a terminology issue. Do you
mean to say, the "RewriteEngine Off" directive cancels the Rewrites
on earlier lines? On how many earlier lines? Etc.

Reese


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 07.01.2010 18:47:17 von Reese

On 07-Jan-10 12:24, Tom Evans wrote:

> "RewriteEngine Off" disables the rewrite engine, so that rewrite rules
> are not applied. Seems unlikely that is what you intended.

It would appear that, by removing the "RewriteEngine Off" line,
the bits on the prior 3 lines now work as expected and intended.

I'd still like to hear more on why that is so.

Testing starts anew.

Reese


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 07.01.2010 18:48:14 von Eric Covener

On Thu, Jan 7, 2010 at 12:36 PM, Reese wrote:

> Do X
> ...does X
> ...after doing X
> Stop doing X
>
> I'm missing something here. Maybe it's a terminology issue. Do you
> mean to say, the "RewriteEngine Off" directive cancels the Rewrites
> on earlier lines? On how many earlier lines? Etc.
>

It turns mod_rewrite off for whatever context it appears in. Config
directives in htaccess are parsed and merged, but not executed, in
order.

--
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 07.01.2010 18:58:44 von Tom Evans

On Thu, Jan 7, 2010 at 5:47 PM, Reese wrote:
> On 07-Jan-10 12:24, Tom Evans wrote:
>
>> "RewriteEngine Off" disables the rewrite engine, so that rewrite rules
>> are not applied. Seems unlikely that is what you intended.
>
> It would appear that, by removing the "RewriteEngine Off" line,
> the bits on the prior 3 lines now work as expected and intended.
>
> I'd still like to hear more on why that is so.
>
> Testing starts anew.
>
> Reese
>

Each directive is fully described in the docs, available online and
installed as part of apache.

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewrit eengine

The first line is edifying:

"The RewriteEngine directive enables or disables the runtime rewriting
engine. If it is set to off this module does no runtime processing at
all. It does not even update the SCRIPT_URx environment variables."

Cheers

Tom

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 07.01.2010 19:08:49 von Patrick Horgan

Reese wrote:
>
> RewriteEngine On
This says, that I want part of the job of httpd is to do rewrites from
this instant until the server is stopped. It's as if a part of httpd is
just sitting there, able to do rewrites, but the switch for it is turned
off to save power if it's not going to be used.
> RewriteCond %{HTTP_HOST} subdomain\.domain\.ext
This says under which conditions I'm going to be wanting the rewriting
to be done.
> RewriteRule (.*)(0[5-6]).html$ /20$2/$1$2.html [R=301,L]
This says what rewriting to do.
> RewriteEngine Off
This says never mind, I didn't mean to hit the switch, let me turn it
back off and turn off the rewriting engine so no rewriting will be done
as httpd does it's job.

Patrick


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 07.01.2010 20:05:29 von Reese

On 07-Jan-10 12:58, Tom Evans wrote:

> http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewrit eengine
>
> The first line is edifying:
>
> "The RewriteEngine directive enables or disables the runtime rewriting
> engine. If it is set to off this module does no runtime processing at
> all. It does not even update the SCRIPT_URx environment variables."

Ah ha. So if it is set to "off" then it is off, period, and things
get dropped through the cracks. That's what it sounds like, anyway.

Testing thus far is sat, I've forwarded test results to the client
with my recommendations on how to proceed.

Thank you, one and all!

Reese



------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 07.01.2010 20:07:33 von Reese

On 07-Jan-10 13:08, Patrick Horgan wrote:

>> RewriteEngine Off
> This says never mind, I didn't mean to hit the switch, let me turn it
> back off and turn off the rewriting engine so no rewriting will be done
> as httpd does it's job.


I grok. Now, I grok better. ;)

Reese


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 09.01.2010 18:54:44 von Reese

I said I would test this,

> RewriteEngine On
> RewriteCond %{HTTP_HOST} subdomain\.domain\.ext
> RewriteRule (.*)(0[5-6]).html$ /20$2/$1$2.html [R=301,L]

Testing had mixed results.

When this rule was at subdomain.domain.ext/sandbox/.htaccess
and the submitted url was

http://subdomain.domain.ext/sandbox/fileDDMMYY.ext

it redirected to http://subdomain.domain.ext/2005/fileDDMMYY.ext
which was the desired and I thought, the expected behavior.

However, when the rule was placed at subdomain.domain.ext/.htaccess
it did not work - it created an endless loop with multiple
insertions of the /2005/ string. For users attempting to reach

http://subdomain.domain.ext/fileDDMMYY.ext

the desired rewrite or redirect URL is

http://subdomain.domain.ext/2005/fileDDMMYY.ext

but this is what happened:

http://subdomain.domain.ext/2005/2005/2005/2005/2005/2005/20 05/2005/2005/2005/2005/2005/2005/2005/2005/2005/2005/2005/20 05/2005/fileDDMMYY.ext

What is really malfunctioning here? Can this rewrite rule be
corrected?

Reese


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 09.01.2010 19:07:43 von Eric Covener

On Sat, Jan 9, 2010 at 12:54 PM, Reese wrote:
> I said I would test this,
>
>> =A0RewriteEngine On
>> =A0RewriteCond %{HTTP_HOST} subdomain\.domain\.ext
>> =A0RewriteRule (.*)(0[5-6]).html$ /20$2/$1$2.html [R=3D301,L]
>
> Testing had mixed results.
>
> When this rule was at subdomain.domain.ext/sandbox/.htaccess
> and the submitted url was
>
> http://subdomain.domain.ext/sandbox/fileDDMMYY.ext
>
> it redirected to http://subdomain.domain.ext/2005/fileDDMMYY.ext
> which was the desired and I thought, the expected behavior.
>
> However, when the rule was placed at subdomain.domain.ext/.htaccess
> it did not work - it created an endless loop with multiple
> insertions of the /2005/ string. For users attempting to reach

To kill the looping:

RewriteCond %{REQUEST_URI} ^/20\d+
or
Change your rewriterule to make sure it doesn't match URI's starting
with digits.

If the 2005 is PATH_INFO, test the [DPI] flag.


--=20
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 09.01.2010 19:37:40 von Reese

On 09-Jan-10 13:07, Eric Covener wrote:

> To kill the looping:
>
> RewriteCond %{REQUEST_URI} ^/20\d+

I tried:

RewriteEngine On
RewriteCond %{HTTP_HOST} subdomain\.domain\.ext
RewriteCond %{REQUEST_URI} ^/20\d+
RewriteRule (.*)(0[5-9]).html$ /20$2/$1$2.html [R=301,L]

For http://subdomain.domain.ext/fileDDMMYY.ext there was no effect,
that file loaded at that URL.

If I specified http://subdomain.domain.ext/2009/fileDDMM09.ext
(the file does exist and is the target of the redirect), then I
received a looping error.

So I tried swapping the positions of the two RewriteCond statements.
That caused an internal server error.

> or
> Change your rewriterule to make sure it doesn't match URI's starting
> with digits.
>
> If the 2005 is PATH_INFO, test the [DPI] flag.

I added DPI to the other flags in the RewriteRule line, it caused
an internal server error.

There's only just so much testing I can do on live files, when
I'm testing voodoo I do not completely understand. I appreciate
the assistance so far, but I'm really grasping at straws and
would appreciate a bit more detail.

Reese



------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 09.01.2010 20:29:16 von Eric Covener

On Sat, Jan 9, 2010 at 1:37 PM, Reese wrote:
> On 09-Jan-10 13:07, Eric Covener wrote:
>
>> To kill the looping:
>>
>> RewriteCond %{REQUEST_URI} ^/20\d+
>
> I tried:
>
> RewriteEngine On
> RewriteCond %{HTTP_HOST} subdomain\.domain\.ext
> RewriteCond %{REQUEST_URI} ^/20\d+
> RewriteRule (.*)(0[5-9]).html$ /20$2/$1$2.html [R=301,L]
>
> For http://subdomain.domain.ext/fileDDMMYY.ext there was no effect,
> that file loaded at that URL.

I think that condition needs negating, because you want your rule to
not have a chance to execute against the rewritten URL that will have
the leading date.

>
> If I specified http://subdomain.domain.ext/2009/fileDDMM09.ext
> (the file does exist and is the target of the redirect), then I
> received a looping error.
>
> So I tried swapping the positions of the two RewriteCond statements.
> That caused an internal server error.

Should not matter.


> I added DPI to the other flags in the RewriteRule line, it caused
> an internal server error.
Only available in the latest few releases.

>
> There's only just so much testing I can do on live files, when
> I'm testing voodoo I do not completely understand. I appreciate
> the assistance so far, but I'm really grasping at straws and
> would appreciate a bit more detail.

Why aren't you working on a test system?


--
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 09.01.2010 21:18:45 von Reese

On 09-Jan-10 14:29, Eric Covener wrote:

>> I tried:
>>
>> RewriteEngine On
>> RewriteCond %{HTTP_HOST} subdomain\.domain\.ext
>> RewriteCond %{REQUEST_URI} ^/20\d+
>> RewriteRule (.*)(0[5-9]).html$ /20$2/$1$2.html [R=301,L]
>>
>> For http://subdomain.domain.ext/fileDDMMYY.ext there was no effect,
>> that file loaded at that URL.
>
> I think that condition needs negating, because you want your rule to
> not have a chance to execute against the rewritten URL that will have
> the leading date.

Which condition needs negating? The one with HTTP_HOST? What
then would keep this rewrite rule from breaking external links
where they also contain a matching NN.html string?

Or did you mean, remove the files we planned removing and then
do testing? It's live files, so the client won't remove them
until after the rewrite rule has been proven to work.

>> If I specified http://subdomain.domain.ext/2009/fileDDMM09.ext
>> (the file does exist and is the target of the redirect), then I
>> received a looping error.
>>
>> So I tried swapping the positions of the two RewriteCond statements.
>> That caused an internal server error.
>
> Should not matter.

And yet, it did. No effect one way, internal server error the other.
It's Apache v2.2.8 running on CentOS v4. something, 4.6 I think.

> Why aren't you working on a test system?

Because I'm not a full-time employee and it isn't cost-effective to
duplicate their system for this one rewrite rule. As I said, it worked
as desired in the sandbox subdirectory, it isn't working when tested
on the live subdomain.

Reese



------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 09.01.2010 21:35:32 von Eric Covener

On Sat, Jan 9, 2010 at 3:18 PM, Reese wrote:
> On 09-Jan-10 14:29, Eric Covener wrote:
>
>>> I tried:
>>>
>>> RewriteEngine On
>>> RewriteCond %{HTTP_HOST} subdomain\.domain\.ext
>>> RewriteCond %{REQUEST_URI} ^/20\d+
>>> RewriteRule (.*)(0[5-9]).html$ /20$2/$1$2.html [R=301,L]
>>>
>>> For http://subdomain.domain.ext/fileDDMMYY.ext there was no effect,
>>> that file loaded at that URL.
>>
>> I think that condition needs negating, because you want your rule to
>> not have a chance to execute against the rewritten URL that will have
>> the leading date.
>
> Which condition needs negating? The one with HTTP_HOST? What
> then would keep this rewrite rule from breaking external links
> where they also contain a matching NN.html string?

The one you added to stop the loping, for REQUEST_URI. You don't want
your rule to run if the URL already begins with a date, so the
condition short circuits.

>
> Or did you mean, remove the files we planned removing and then
> do testing? It's live files, so the client won't remove them
> until after the rewrite rule has been proven to work.
>
>>> If I specified http://subdomain.domain.ext/2009/fileDDMM09.ext
>>> (the file does exist and is the target of the redirect), then I
>>> received a looping error.
>>>
>>> So I tried swapping the positions of the two RewriteCond statements.
>>> That caused an internal server error.
>>
>> Should not matter.
>
> And yet, it did. No effect one way, internal server error the other.
> It's Apache v2.2.8 running on CentOS v4. something, 4.6 I think.
>

Would have to see your corresponding errorlog entry, and the htaccess
file at the time the error was generated, but I don't think swapping
two conditions is likely to trigger an ISE.

--
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

RE: Mod_Rewrite voodoo

am 11.01.2010 15:43:18 von Oliver Schoenborn

> From: Reese [mailto:howell.r@inkworkswell.com]
>=20
> >> I tried:
> >>
> >> RewriteEngine On
> >> RewriteCond %{HTTP_HOST} subdomain\.domain\.ext
> >> RewriteCond %{REQUEST_URI} ^/20\d+
> >> RewriteRule (.*)(0[5-9]).html$ /20$2/$1$2.html [R=3D301,L]
> >>
> >> For http://subdomain.domain.ext/fileDDMMYY.ext there was no effect,
> >> that file loaded at that URL.
> >
> > I think that condition needs negating, because you want your rule to
> > not have a chance to execute against the rewritten URL that will have
> > the leading date.
>=20
> Which condition needs negating? The one with HTTP_HOST? What
> then would keep this rewrite rule from breaking external links
> where they also contain a matching NN.html string?

Reese, you really ought to take a closer look at the mod rewrite directives=
.. A RewriteCond is a condition that must be verified (ie evaluate to TRUE) =
in order for the associated RewriteRule to be executed. So your=20

RewriteCond %{REQUEST_URI} ^/20\d+

will cause

RewriteRule (.*)(0[5-9]).html$ /20$2/$1$2.html [R=3D301,L]

to be applied ONLY if the URL request starts with /20 followed by at least =
one digit (/200, /2000, etc). This is clearly the opposite of what you want=
: you want the rewrite rule to be executed only if the URL request does NOT=
start with that string.=20

Also, why are you concerned with external links? External links, when click=
ed by user, will go to servers outside of your domain so your server will n=
ever see the request. The rewrite module works on the HTTP request to its s=
erver, not on the body (HTML) of request responses.=20

Oliver


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Mod_Rewrite voodoo

am 12.01.2010 01:04:27 von Reese

We did testing on this over the weekend, the rewrite rule went live
Sunday night. As of this writing, there are a few minor issues not
related to the rewrite rule, they are related to moving files around
after the rewrite rule was tested. So this seems like a done deal.

Thank you to all who provided assistance.

Reese


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org